package org.example.Server.controller.unit;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.unit.Unit;
import org.example.Server.model.unit.UnitReDTO;
import org.example.Server.service.unit.UnitTeachService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/youxich/unit/teacher")
public class UnitTeachController {
    @Autowired
    UnitTeachService unitTeachService;

    /**
     * 添加课堂章节或者小节
     *
     * @param unit
     * @return
     */
    @PostMapping("")
    public ResultAPI addUnit(@RequestBody Unit unit) {
        return unitTeachService.addUnit(unit);
    }

    /**
     * 添加课堂资源
     *
     * @param unitReDTO
     * @return
     */
    @PostMapping("resource")
    public ResultAPI addUnitRe(@RequestBody UnitReDTO unitReDTO) {
        return unitTeachService.addUnitRe(unitReDTO);
    }

    /**
     * 更新单元命名
     *
     * @param unit
     * @return
     */
    @PatchMapping
    public ResultAPI updateUnit(@RequestBody Unit unit) {
        return unitTeachService.updateUnit(unit);
    }

    /**
     * 删除章节或小节
     *
     * @param ids
     * @return
     */
    @DeleteMapping("{ids}")
    public ResultAPI deleteUnits(@PathVariable("ids") List<Integer> ids) {
        return unitTeachService.deleteUnits(ids);
    }

    /**
     * 删除单元资源
     *
     * @param unit_re_ids
     * @return
     */
    @DeleteMapping("resource/{unit_re_ids}")
    public ResultAPI delUnitRes(@PathVariable("unit_re_ids") List<Integer> unit_re_ids) {
        return unitTeachService.delUnitRes(unit_re_ids);
    }

}
